home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 64
/
Volume 64 - JOGO DISK .iso
/
Games
/
the_best_every_day.swf
/
scripts
/
__Packages
/
Patrick.as
< prev
next >
Wrap
Text File
|
2008-04-10
|
17KB
|
583 lines
class Patrick extends sarbakan.visual.element.DynamicElement
{
static var NUMBER_SPEED_X = 3;
static var NUMBER_SPEED_Y = 2;
static var NUMBER_PATRICK_MEMORY = 30;
static var NUMBER_SCREEN_WIDTH = 600;
static var NUMBER_SCREEN_HEIGHT = 300;
static var NUMBER_HUD_ADJUST = 65;
static var NUMBER_EASTEREGG = 46;
var DEFAULT_STATE = "Start";
var nTimeViewPoint = 50;
function Patrick(l_mcPatrick, l_oLevel, l_nMaxStrength)
{
super(l_mcPatrick._name);
this.setMC(l_mcPatrick);
this.keyListener = new Object();
this.enable();
this.oLevel = l_oLevel;
this.oConfusionTime = undefined;
this.nMaxStrength = l_nMaxStrength;
this.nStrength = this.nMaxStrength;
this.nStrengthDivider = this.nMaxStrength / 60;
this.bActive = false;
this.bTrapped = false;
this.bLadder = false;
this.nTimeSpend = 0;
this.mcArrow = this.mc._parent._parent.Arrow_mc;
}
function setAction(l_sAction)
{
if(this.bActive && !this.bTrapped)
{
this.l_sAction();
}
if(this.mc._parent._parent.mcSpongebob._currentframe != Patrick.NUMBER_EASTEREGG)
{
this.mc._parent._parent.mcSpongebob.gotoAndStop(l_sAction);
if(this.mc._parent._parent.mcSpongebob.state._currentframe == this.mc._parent._parent.mcSpongebob.state._totalframes)
{
this.mc._parent._parent.mcSpongebob.state.gotoAndPlay(1);
}
}
}
function update()
{
super.update();
if(this.bActive)
{
if(this.sState == "Move")
{
this.StrengthManagement();
}
this.FearEdge();
this.CheckConfusion();
if(this.fLoopFunction)
{
this.fLoopFunction();
}
if(this.oTime)
{
this.oTime.update();
if(this.oTime.__get__timeOut())
{
this.fLoopFunction = undefined;
}
}
this.placeArrow();
}
else if(this.mcArrow._currentframe != 1)
{
this.mcArrow.gotoAndStop(1);
}
}
function setControls(l_mcControls)
{
this.keyListener.onKeyDown = function()
{
if(!_global.C.oGame.bMiniGame && !_global.Pack.bPaused)
{
if(Key.isDown(38))
{
_global.C.oGame.oLevel.oPatrick.setAction("MoveUp");
}
else if(Key.isDown(37))
{
_global.C.oGame.oLevel.oPatrick.setAction("MoveLeft");
}
else if(Key.isDown(39))
{
_global.C.oGame.oLevel.oPatrick.setAction("MoveRight");
}
else if(Key.isDown(40))
{
_global.C.oGame.oLevel.oPatrick.setAction("MoveDown");
}
else if(Key.isDown(32))
{
_global.C.oGame.oLevel.oPatrick.setAction("DropBoxHere");
}
else if(Key.isDown(77))
{
_global.C.oGame.oLevel.oPatrick.setAction("CheerUp");
}
else if(Key.getCode() == 187 || Key.getCode() == 107)
{
_global.C.oGame.oLevel.oPatrick.setAction("EasterEgg");
}
}
};
Key.addListener(this.keyListener);
}
function ClearControls()
{
Key.removeListener(this.keyListener);
}
function trap(l_bTrapped, l_mcObstacle)
{
this.bTrapped = l_bTrapped;
if(_global.C.oGame.bGamePlaying)
{
if(this.bTrapped)
{
switch(l_mcObstacle.getType())
{
case "Bubbles":
this.mc.gotoAndStop("Idle");
this.mc.state.Bras.gotoAndStop(2);
this.nSpeedX = 0;
this.nSpeedY = 0;
this.fLoopFunction = undefined;
break;
case "Banana":
case "Slobber":
this.setState("BoxLost");
this.nSpeedX = 0;
this.nSpeedY = 0;
this.fLoopFunction = undefined;
l_mcObstacle.fRemove();
_global.C.dropBox(false);
this.nStrength = this.nMaxStrength;
break;
case "Gary":
this.bTrapped = false;
}
}
}
}
function win()
{
this.Idle();
this.setState("Winner");
this.mc.gotoAndStop("Winner");
super.update();
this.bActive = false;
}
function Winner()
{
if(this.mc.state._currentframe == this.mc.state._totalframes)
{
this.setState("Idle");
_global.C.oGame.EndGame(true);
}
}
function getCamCoord()
{
return {x:this.mc._x - Patrick.NUMBER_HUD_ADJUST - Patrick.NUMBER_SCREEN_WIDTH / 2,y:this.mc._y - Patrick.NUMBER_SCREEN_HEIGHT / 2};
}
function StrengthManagement()
{
if(this.nStrength > 0)
{
this.nStrength = this.nStrength - 1;
this.mc.state.mc_Arm.gotoAndStop(Math.ceil((this.nMaxStrength - this.nStrength) / this.nStrengthDivider));
this.mc.state.Bras.BrasAnim.gotoAndStop(Math.ceil((this.nMaxStrength - this.nStrength) / this.nStrengthDivider));
if(this.nStrength == 0)
{
this.Idle();
this.nStrength = this.nMaxStrength;
this.setState("DropBox");
this.mc.gotoAndStop("DropBox");
this.bActive = false;
if(!this.collideWithMap("floor",this.mc.mcEdgeDetector))
{
this.mc._xscale *= -1;
}
_global.C.dropBox(false);
this.fLoopFunction = undefined;
}
}
}
function Ballance()
{
this.bActive = false;
this.nSpeedX = 0;
this.nSpeedY = 0;
if(this.mc.state._currentframe == this.mc.state._totalframes)
{
this.setState("ViewPoint");
this.mc.gotoAndStop("ViewPoint");
this.oLevel.setNewDropPoint();
this.mc._xscale *= -1;
}
}
function FearEdge()
{
if(!this.collideWithMap("floor",this.mc.mcEdgeDetector) && this.nSpeedX != 0 && this.mc._y < 300)
{
this.setState("Ballance");
this.mc.gotoAndStop("Winner");
this.nStrength = this.nMaxStrength;
this.bActive = false;
_global.C.dropBox(false);
this.fLoopFunction = undefined;
}
else if(!this.collideWithMap("floor",this.mc.mcEdgeDetector) && this.nSpeedX != 0 && this.mc._y > 300)
{
this.nSpeedX *= -1;
}
}
function CheckConfusion()
{
if(this.oConfusionTime != undefined)
{
this.oConfusionTime.update();
if(this.oConfusionTime.__get__timeOut())
{
this.oConfusionTime = undefined;
}
}
}
function Idle()
{
this.nSpeedX = 0;
this.nSpeedY = 0;
}
function DropBox()
{
this.bActive = false;
this.nSpeedX = 0;
this.nSpeedY = 0;
if(this.mc.state._currentframe == this.mc.state._totalframes)
{
this.setState("ViewPoint");
this.mc.gotoAndStop("ViewPoint");
this.oLevel.setNewDropPoint();
}
}
function BoxLost()
{
this.bActive = false;
this.nSpeedX = 0;
this.nSpeedY = 0;
if(this.mc.state._currentframe == this.mc.state._totalframes)
{
this.setState("ViewPoint");
this.mc.gotoAndStop("ViewPoint");
this.oLevel.setNewDropPoint();
}
}
function BoxDown()
{
this.nSpeedX = 0;
this.nSpeedY = 0;
this.bActive = false;
if(this.mc.state._currentframe == this.mc.state._totalframes)
{
this.setState("ViewPoint");
this.mc.gotoAndStop("ViewPoint");
this.oLevel.setNewDropPoint();
}
}
function BoxReceive()
{
if(this.mc.state._currentframe == this.mc.state._totalframes)
{
this.bActive = true;
this.nSpeedY = 0;
this.setState("Move");
if(this.mc._xscale == 100)
{
this.nSpeedX = Patrick.NUMBER_SPEED_X;
}
else
{
this.nSpeedX = - Patrick.NUMBER_SPEED_X;
}
}
}
function ViewPoint()
{
this.bActive = false;
this.oConfusionTime = undefined;
this.nStrength = this.nMaxStrength;
this.bTrapped = false;
this.setState("Idle");
if(_global.Pack.nFunds >= 0)
{
this.oLevel.oCam.travelTo(this.mc._parent[this.sDropPoint]._x - Patrick.NUMBER_HUD_ADJUST - Patrick.NUMBER_SCREEN_WIDTH / 2,this.mc._parent[this.sDropPoint]._y - Patrick.NUMBER_SCREEN_HEIGHT / 2,this.CamReturn);
}
}
function Start()
{
this.mc.gotoAndStop("Idle");
this.nTimeSpend = this.nTimeSpend + 1;
if(this.nTimeSpend > 50)
{
this.nTimeSpend = 0;
this.setState("ViewPoint");
this.mc.gotoAndStop("ViewPoint");
}
}
function CamReturn()
{
_global.C.oGame.oLevel.oPatrick.setState("BoxReceive");
_global.C.oGame.oLevel.oPatrick.mc.gotoAndStop("BoxReceive");
_global.C.oGame.oLevel.oCam.travelTo(_global.C.oGame.oLevel.oPatrick.mc._x - Patrick.NUMBER_HUD_ADJUST - Patrick.NUMBER_SCREEN_WIDTH / 2,_global.C.oGame.oLevel.oPatrick.mc._y - Patrick.NUMBER_SCREEN_HEIGHT / 2);
}
function MoveLeft()
{
if(this.oConfusionTime && !this.bLadder)
{
if(this.sLastArrow != "Left")
{
this.nStrength = 1;
this.StrengthManagement();
}
}
else if(!this.bLadder)
{
this.sLastArrow = "Left";
this.oConfusionTime = new sarbakan.utils.Time(0,0);
this.oConfusionTime.__set__frames(10);
this.nSpeedX = - Patrick.NUMBER_SPEED_X;
this.nSpeedY = 0;
this.setState("Move");
}
else
{
this.sTimedNextAction = "MoveLeft";
}
}
function MoveRight()
{
if(this.oConfusionTime && !this.bLadder)
{
if(this.sLastArrow != "Right")
{
this.nStrength = 1;
this.StrengthManagement();
}
}
else if(!this.bLadder)
{
this.sLastArrow = "Right";
this.oConfusionTime = new sarbakan.utils.Time(0,0);
this.oConfusionTime.__set__frames(10);
this.nSpeedX = Patrick.NUMBER_SPEED_X;
this.nSpeedY = 0;
this.setState("Move");
}
else
{
this.sTimedNextAction = "MoveRight";
}
}
function CheerUp()
{
this.nStrength += 150;
this.nStrength = Math.min(this.nStrength,this.nMaxStrength);
}
function MoveDown()
{
if(this.sState == "Move")
{
if(this.LadderCollide(-15))
{
this.nSpeedX = 0;
this.nTimeSpend = 0;
this.nSpeedY = Patrick.NUMBER_SPEED_Y;
this.setState("DownLadder");
this.fLoopFunction = this.loopLadderDown;
this.bLadder = true;
this.oTime = undefined;
}
else
{
this.oTime = new sarbakan.utils.Time(0,1);
this.oTime.__set__frames(12);
this.fLoopFunction = this.loopFindLadderDown;
}
}
}
function loopLadderDown()
{
this.nTimeSpend = this.nTimeSpend + 1;
if(this.nTimeSpend >= 10)
{
if(!this.LadderCollide(5))
{
if(!this.sTimedNextAction)
{
this.setRandomDirection();
}
else
{
this.setAction(this.sTimedNextAction);
}
this.mc._y -= Patrick.NUMBER_SPEED_Y;
this.fLoopFunction = undefined;
this.bLadder = false;
}
}
}
function loopFindLadderDown()
{
if(this.LadderCollide(-15))
{
this.oTime = undefined;
this.nSpeedX = 0;
this.nTimeSpend = 0;
this.nSpeedY = Patrick.NUMBER_SPEED_Y;
this.setState("DownLadder");
this.fLoopFunction = this.loopLadderDown;
this.bLadder = true;
}
}
function MoveUp()
{
if(this.sState == "Move")
{
if(this.LadderCollide(15))
{
this.nSpeedX = 0;
this.nTimeSpend = 0;
this.nSpeedY = - Patrick.NUMBER_SPEED_Y;
this.setState("UpLadder");
this.fLoopFunction = this.loopLadderUp;
this.bLadder = true;
this.oTime = undefined;
}
else
{
this.oTime = new sarbakan.utils.Time(0,1);
this.oTime.__set__frames(12);
this.fLoopFunction = this.loopFindLadderUp;
}
}
}
function loopLadderUp()
{
this.nTimeSpend = this.nTimeSpend + 1;
if(this.nTimeSpend >= 10)
{
if(!this.LadderCollide(-5))
{
if(!this.sTimedNextAction)
{
this.setRandomDirection();
}
else
{
this.setAction(this.sTimedNextAction);
}
this.mc._y += Patrick.NUMBER_SPEED_Y;
this.fLoopFunction = undefined;
this.bLadder = false;
}
}
}
function loopFindLadderUp()
{
if(this.LadderCollide(15))
{
this.oTime = undefined;
this.nSpeedX = 0;
this.nTimeSpend = 0;
this.nSpeedY = - Patrick.NUMBER_SPEED_Y;
this.setState("UpLadder");
this.fLoopFunction = this.loopLadderUp;
this.bLadder = true;
}
}
function LadderCollide(_modifier)
{
var _loc4_ = false;
var _loc3_ = this.mc.mcDetector.getBounds(_global.GS);
var _loc6_ = (_loc3_.xMax + _loc3_.xMin) / 2;
var _loc5_ = _loc3_.yMax - _modifier;
if(this.mc._parent.Ladders.hitTest(_loc6_,_loc5_,true))
{
_loc4_ = true;
}
else
{
this.bLadder = false;
}
return _loc4_;
}
function DropPointCollide()
{
var _loc2_ = false;
if(this.mc.hitTest(this.mc._parent[this.sDropPoint]) && this.getElement(this.sDropPoint).mc._currentframe == 1)
{
_loc2_ = true;
}
return _loc2_;
}
function DropBoxHere()
{
if(!this.bLadder && this.DropPointCollide())
{
this.setState("BoxDown");
this.mc.gotoAndStop("BoxDown");
_global.C.dropBox(true);
}
else if(!this.bLadder)
{
this.setState("BoxDown");
this.mc.gotoAndStop("BoxDown");
_global.C.dropBox(false);
}
}
function setRandomDirection()
{
this.nSpeedY = 0;
this.setState("Move");
var _loc2_ = Math.ceil(Math.random() * 2);
if(_loc2_ == 1)
{
this.nSpeedX = - Patrick.NUMBER_SPEED_X;
}
else
{
this.nSpeedX = Patrick.NUMBER_SPEED_X;
}
}
function set dropPoint(l_sDropPoint)
{
this.sDropPoint = l_sDropPoint;
}
function placeArrow()
{
var _loc3_ = false;
var _loc2_ = "";
if(Math.abs(this.mc._y - this.mc._parent[this.sDropPoint]._y) > 100)
{
_loc3_ = true;
if(this.mc._y - this.mc._parent[this.sDropPoint]._y > 0)
{
_loc2_ += "U";
}
else
{
_loc2_ += "D";
}
}
if(Math.abs(this.mc._x - this.mc._parent[this.sDropPoint]._x) > 250)
{
_loc3_ = true;
if(this.mc._x - this.mc._parent[this.sDropPoint]._x > 0)
{
_loc2_ += "L";
}
else
{
_loc2_ += "R";
}
}
else if(Math.abs(this.mc._y - this.mc._parent[this.sDropPoint]._y) < 150)
{
_loc3_ = false;
}
if(_loc3_)
{
this.mcArrow.gotoAndStop(_loc2_);
}
else
{
this.mcArrow.gotoAndStop(1);
}
}
}